<HTML> 
<HEAD> 
	<TITLE>3rd Party ROBOTC Drivers</TITLE> 
<link href="tabs.css" rel="stylesheet" type="text/css"/> 
<link href="doxygen.css" rel="stylesheet" type="text/css"/> 
</HEAD> 
 
<BODY bgcolor="#ffffff" link="#000000" vlink="#000000"> 
<table width="100%" bgcolor="navy" cellspacing=0 cellpadding=1 border=0> 
<tr><td><table width="100%" bgcolor="#EEEEDD" cellspacing=0 cellpadding=3 border=0> 
<tr> 
    <td width="33%" align="left"> <img src="images/LOGO_NXT.gif" width=266 height=44 border="0" alt="Mindstorms"></td> 
    <td><b><font size="+3" color="navy">3rd Party ROBOTC Drivers</font></b></td> 
    <td align="right"> <img src="images/logo.png" width=44 height=44 border="0" alt="RobotC"></td>     
</tr> 
  <tr bgcolor="#cccc99" align="right"> 
          <td colspan=3> <font face="arial" size="-1"> [<a href=main.html>Home</a>] [<a target=_top href="https://sourceforge.net/projects/rdpartyrobotcdr/">Download</a>] [<a target=_top href="http://apps.sourceforge.net/mantisbt/rdpartyrobotcdr/my_view_page.php">Submit a bug/suggestion</a>]  [<a target=_top href="http://www.robotc.net/forums/">ROBOTC Forums</a>] [<a target=_top href="http://botbench.com">Blog</a>] [<a target=_top href="http://sourceforge.net/donate/index.php?group_id=257238">Support this project</a>]</font> </td> 
</tr> 
</table></td></tr> 
</table> 
<!-- Generated by Doxygen 1.7.2 -->
<div class="header">
  <div class="headertitle">
<h1>lego-light-SMUX-test1.c</h1>  </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><span class="preprocessor">#pragma config(Sensor, S1,     HTSMUX,              sensorI2CCustom)</span>
<span class="preprocessor"></span><span class="comment">//*!!Code automatically generated by &#39;ROBOTC&#39; configuration wizard               !!*//</span>

<span class="comment">/*</span>
<span class="comment"> * $Id: lego-light-SMUX-test1.c 133 2013-03-10 15:15:38Z xander $</span>
<span class="comment"> */</span>
<span class="comment"></span>
<span class="comment">/**</span>
<span class="comment"> * lego-light.h provides an API for the Lego Light Sensor.  This program</span>
<span class="comment"> * demonstrates how to use that API through a SMUX.</span>
<span class="comment"> *</span>
<span class="comment"> * Changelog:</span>
<span class="comment"> * - 0.1: Initial release</span>
<span class="comment"> * - 0.2: More comments</span>
<span class="comment"> *</span>
<span class="comment"> * License: You may use this code as you wish, provided you give credit where it&#39;s due.</span>
<span class="comment"> *</span>
<span class="comment"> * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 3.59 AND HIGHER. </span>
<span class="comment"></span>
<span class="comment"> * Xander Soldaat (xander_at_botbench.com)</span>
<span class="comment"> * 25 November 2009</span>
<span class="comment"> * version 0.2</span>
<span class="comment"> */</span>

<span class="preprocessor">#include &quot;<a class="code" href="hitechnic-sensormux_8h.html" title="Commonly used functions used by drivers.">drivers/hitechnic-sensormux.h</a>&quot;</span>
<span class="preprocessor">#include &quot;<a class="code" href="lego-light_8h.html" title="Lego Light Sensor driver.">drivers/lego-light.h</a>&quot;</span>

<span class="comment">// The sensor is connected to the first port</span>
<span class="comment">// of the SMUX which is connected to the NXT port S1.</span>
<span class="comment">// To access that sensor, we must use msensor_S1_1.  If the sensor</span>
<span class="comment">// were connected to 3rd port of the SMUX connected to the NXT port S4,</span>
<span class="comment">// we would use msensor_S4_3</span>

<span class="comment">// Give the sensor a nice easy to use name</span>
<span class="keyword">const</span> <a class="code" href="group__htsmux.html#gab5bad1759ac110c43e66c3ec54047f42">tMUXSensor</a> LEGOLS = <a name="a0"></a><a class="code" href="group__htsmux.html#ggab5bad1759ac110c43e66c3ec54047f42a9bb0d1a5225e16291efdef5795191af1">msensor_S1_1</a>;

task main() {
  <span class="keywordtype">int</span> raw = 0;
  <span class="keywordtype">int</span> nrm = 0;
  <span class="keywordtype">bool</span> active = <span class="keyword">true</span>;

  <span class="comment">// Turn the light on</span>
  <a name="a1"></a><a class="code" href="group__legols.html#gaa8ba995bb855d1ecfb83bf00520305c8">LSsetActive</a>(LEGOLS);

  nNxtButtonTask  = -2;

  nxtDisplayCenteredTextLine(0, <span class="stringliteral">&quot;Lego&quot;</span>);
  nxtDisplayCenteredBigTextLine(1, <span class="stringliteral">&quot;LIGHT&quot;</span>);
  nxtDisplayCenteredTextLine(3, <span class="stringliteral">&quot;SMUX Test&quot;</span>);
  nxtDisplayCenteredTextLine(5, <span class="stringliteral">&quot;Connect SMUX to&quot;</span>);
  nxtDisplayCenteredTextLine(6, <span class="stringliteral">&quot;S1 and sensor to&quot;</span>);
  nxtDisplayCenteredTextLine(7, <span class="stringliteral">&quot;SMUX Port 1&quot;</span>);
  wait1Msec(2000);

  nxtDisplayClearTextLine(7);
  nxtDisplayTextLine(5, <span class="stringliteral">&quot;Press [enter]&quot;</span>);
  nxtDisplayTextLine(6, <span class="stringliteral">&quot;to toggle light&quot;</span>);
  wait1Msec(2000);

  <span class="keywordflow">while</span> (<span class="keyword">true</span>) {
    <span class="comment">// The enter button has been pressed, switch</span>
    <span class="comment">// to the other mode</span>
    <span class="keywordflow">if</span> (nNxtButtonPressed == kEnterButton) {
      active = !active;
      <span class="keywordflow">if</span> (!active)
        <a name="a2"></a><a class="code" href="group__legols.html#ga671dd080a42221c7cf93b020198ef387">LSsetInactive</a>(LEGOLS);
      <span class="keywordflow">else</span>
        <a class="code" href="group__legols.html#gaa8ba995bb855d1ecfb83bf00520305c8">LSsetActive</a>(LEGOLS);

      <span class="comment">// wait 500ms to debounce the switch</span>
      wait1Msec(500);
    }

    nxtDisplayClearTextLine(5);
    nxtDisplayClearTextLine(6);
    raw = <a name="a3"></a><a class="code" href="group__legols.html#ga6b009301ef0d572809db2a8f0a0a071c">LSvalRaw</a>(LEGOLS);
    nrm = <a name="a4"></a><a class="code" href="group__legols.html#gad395c77af6c328077d1d09227937ecda">LSvalNorm</a>(LEGOLS);
    nxtDisplayTextLine(5, <span class="stringliteral">&quot;Raw:  %4d&quot;</span>, raw);
    nxtDisplayTextLine(6, <span class="stringliteral">&quot;Norm: %4d&quot;</span>, nrm);
    wait1Msec(50);
  }
}

<span class="comment">/*</span>
<span class="comment"> * $Id: lego-light-SMUX-test1.c 133 2013-03-10 15:15:38Z xander $</span>
<span class="comment"> */</span>
</pre></div> </div>
</div>
<hr class="footer"/><address class="footer"><small>Generated on Wed Mar 13 2013 19:56:42 for ROBOTC Drivers by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.2 </small></address>
</body>
</html>
